package edu.ubb.remeye.gui.internationalization;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 * Language resources manager class.
 * 
 * @author Andrew Ianicicau
 *
 */
public class LanguageManager {

	///////////////////////////////////////////////////////////////////////////////////
	////		ATTRIBUTES - LanguageManager
	///////////////////////////////////////////////////////////////////////////////////

	/**
	 * Instance of this class.
	 */
	private static LanguageManager languageManager;
	
	/**
	 * Current locale.
	 */
	private Locale currentLocale;
	
	/**
	 * Resource bundle to manage resource bundles.
	 */
	private ResourceBundle langauges;
	
	/**
	 * Location of resource bundles.
	 */
	private static final String LANGUAGE_RESOURCES = "edu.ubb.remeye.gui.internationalization.languages.lang";

	
	
	///////////////////////////////////////////////////////////////////////////////////
	////		CONSTRUCTORS - LanguageManager
	///////////////////////////////////////////////////////////////////////////////////

	private LanguageManager() {
		currentLocale = new Locale("en", "EN");
		langauges = ResourceBundle.getBundle(LANGUAGE_RESOURCES, currentLocale);
	}

	
	
	///////////////////////////////////////////////////////////////////////////////////
	////		METHODS - LanguageManager
	///////////////////////////////////////////////////////////////////////////////////
	
	/**
	 * Singleton design pattern instance provider method.
	 */
	public static LanguageManager getLanguageManager() {
		if(languageManager == null)
			languageManager = new LanguageManager();
		return languageManager;
	}
	
	/**
	 * Set the locale to use.
	 * @param locale Locale to use.
	 */
	public void setCurrentLocale(Locale locale) {
		languageManager.currentLocale = locale;
		languageManager.langauges = ResourceBundle.getBundle(LANGUAGE_RESOURCES, languageManager.currentLocale);
	}
	
	/**
	 * Get the text according to key and current locale.
	 * @param key Key for text.
	 * @return The text found with the key.
	 */
	public String getText(String key) {
		return langauges.getString(key);
	}

}
